<?php

require_once('includes/Database.php');

$db = new Database('localhost', 'root', 'root', 'amantes');
//$db = new Database('db514712296.db.1and1.com', 'dbo514712296', 'S#y4maNT3', 'db514712296');
$db->connect();
$isValid = TRUE;
$input = array();

if(!isset($_POST['sexo']) ||
!isset($_POST['edad']) ||
!isset($_POST['n1']) ||
!isset($_POST['n2']) ||
!isset($_POST['n3']) ||
!isset($_POST['n4']) ||
!isset($_POST['n5']) ||
!isset($_POST['n6']) ||
!isset($_POST['n7']) ||
!isset($_POST['n8']) ||
!isset($_POST['n9']) ||
!isset($_POST['n10']) ||
!isset($_POST['n11']) ||
!isset($_POST['n12']) ||
!isset($_POST['n13']) ||
!isset($_POST['n14']) ||
!isset($_POST['n15']) ||
!isset($_POST['n16']) ||
!isset($_POST['n17']) ||
!isset($_POST['n18']) ||
!isset($_POST['n19']) ||
!isset($_POST['n20']) ||
!isset($_POST['n21']) ||
!isset($_POST['n22']) ||
!isset($_POST['n23']) ||
!isset($_POST['n24'])) {
	$isValid = FALSE;
}

if($isValid) {
	$input['sexo'] = $_POST['sexo'] === 'V' ? 'Varón' : 'Mujer';
	$input['edad'] = is_numeric($_POST['edad']) ? $_POST['edad'] : 18;
	$input['edad'] = $input['edad'] > 11 && $input['edad'] < 101 ? $input['edad'] : 18;
	$input['pregunta1_eros'] = $_POST['n1'];
	$input['pregunta2_eros'] = $_POST['n2'];
	$input['pregunta3_eros'] = $_POST['n3'];
	$input['pregunta4_eros'] = $_POST['n4'];
	$input['pregunta5_ludus'] = $_POST['n5'];
	$input['pregunta6_ludus'] = $_POST['n6'];
	$input['pregunta7_ludus'] = $_POST['n7'];
	$input['pregunta8_ludus'] = $_POST['n8'];
	$input['pregunta9_storge'] = $_POST['n9'];
	$input['pregunta10_storge'] = $_POST['n10'];
	$input['pregunta11_storge'] = $_POST['n11'];
	$input['pregunta12_storge'] = $_POST['n12'];
	$input['pregunta13_pragma'] = $_POST['n13'];
	$input['pregunta14_pragma'] = $_POST['n14'];
	$input['pregunta15_pragma'] = $_POST['n15'];
	$input['pregunta16_pragma'] = $_POST['n16'];
	$input['pregunta17_mania'] = $_POST['n17'];
	$input['pregunta18_mania'] = $_POST['n18'];
	$input['pregunta19_mania'] = $_POST['n19'];
	$input['pregunta20_mania'] = $_POST['n20'];
	$input['pregunta21_agape'] = $_POST['n21'];
	$input['pregunta22_agape'] = $_POST['n22'];
	$input['pregunta23_agape'] = $_POST['n23'];
	$input['pregunta24_agape'] = $_POST['n24'];
}

// TODO: Validar $input

if($isValid) {
	if($db->query_insert('test', $input)) echo 'success!';
}

$db->close();

// End of file